package com.androiddoc.randomgame;

import min3d.core.RendererActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.LinearLayout;

import com.androiddoc.randomgame.mycompnents.FlashView;
import com.flurry.android.FlurryAgent;
import com.androiddoc.randomgame.R;

public class GameDice extends RendererActivity implements View.OnClickListener{
	private FlashView coin;
	private final static int CHANGE_COIN = 0;
	private boolean isRolling = false;
	private LinearLayout customCavas;
	private Handler mHandler = new Handler(){
		@Override
		public void handleMessage(android.os.Message msg) {
			switch(msg.what){
			case CHANGE_COIN:
				int random = (int) (Math.random() * 6);
				coin.stop(random);
				break;
			}
			
		};
	};
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dice);
        customCavas = (LinearLayout) findViewById(R.id.other);
        customCavas.addView(_glSurfaceView);
        coin = (FlashView) findViewById(R.id.coin);
        coin.initFlashBitmaps(new int[]{
        		R.drawable.dice1,
        		R.drawable.dice2,
        		R.drawable.dice3,
        		R.drawable.dice4,
        		R.drawable.dice5,
        		R.drawable.dice6
        		});
        coin.setVisibility(View.VISIBLE);
        coin.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
    	FlurryAgent.logEvent("dice_game");
    	switch(v.getId()){
    	case R.id.play:
    		if(isRolling){
    			mHandler.sendEmptyMessage(CHANGE_COIN);
				isRolling = false;
    		} else {
    			coin.start();
    			isRolling = true;
    		}
    		break;
    		default:
    			break;
    	}

    	
    }
}
